# Copyright (c) 2021 Presto Labs Pte. Ltd.
# Author: fengyang

import requests
from coin2.exchange.product_info import ProductInfoDefault
from coin2.exchange.symbology import SymbologyInfo


def generate():
  mea = 'Futures.Dydx.v3'
  me = 'Futures.Dydx'
  default = ProductInfoDefault()
  symbol_info = SymbologyInfo()
  data = requests.get('https://api.dydx.exchange/v3/markets').json()['markets']

  pis = []
  for symbol, info in data.items():
    native_symbol = symbol
    native_base = info['baseAsset']
    native_quote = info['quoteAsset']
    base = symbol_info.native_to_norm_currency(mea, native_base)
    quote = symbol_info.native_to_norm_currency(mea, native_quote)
    symbol = "%s-%s.PERPETUAL" % (base, quote)

    pi = dict(symbol=symbol,
              base=base,
              quote=quote,
              native_symbol=native_symbol,
              native_base=native_base,
              native_quote=native_quote,
              price_ticksize=float(info['tickSize']),
              qty_ticksize=float(info['stepSize']),
              min_qty=float(info['minOrderSize']),
              is_inverse=False,
              contract_value=float(1))
    pi = {**pi, **default.product_info(me, symbol)}
    pis.append(pi)

  pis = sorted(pis, key=lambda x: x['symbol'])
  return pis


if __name__ == "__main__":
  import json
  print(json.dumps(generate(), indent=2))
